using ClownFish;
using System;
using System.Collections;
using System.Data;
using System.Data.Common;
using System.Data.Odbc;
using System.Data.OleDb;
using System.Data.SqlClient;
using System.Reflection;

internal static class Class7
{
	private static Hashtable hashtable_0 = new Hashtable(3072);

	public static DbParameter[] smethod_0(DbConnection dbConnection_0, string string_0)
	{
		if (dbConnection_0 == null)
		{
			throw new ArgumentNullException("dbConn");
		}
		if (string.IsNullOrEmpty(string_0))
		{
			throw new ArgumentNullException("spName");
		}
		DbCommand dbCommand = null;
		using (DbConnection dbConnection = (DbConnection)((ICloneable)dbConnection_0).Clone())
		{
			dbCommand = dbConnection.CreateCommand();
			dbCommand.CommandText = string_0;
			dbCommand.CommandType = CommandType.StoredProcedure;
			dbConnection.Open();
			if (dbCommand is SqlCommand)
			{
				SqlCommandBuilder.DeriveParameters((SqlCommand)dbCommand);
			}
			else if (dbCommand is OleDbCommand)
			{
				OleDbCommandBuilder.DeriveParameters((OleDbCommand)dbCommand);
			}
			else if (dbCommand is OdbcCommand)
			{
				OdbcCommandBuilder.DeriveParameters((OdbcCommand)dbCommand);
			}
			else
			{
				DbProviderFactory dbProviderFactory = Class23.smethod_2(dbConnection_0.GetType());
				if (dbProviderFactory == null)
				{
					throw new NotSupportedException();
				}
				DbCommandBuilder dbCommandBuilder = dbProviderFactory.CreateCommandBuilder();
				dbCommandBuilder.GetType().InvokeMember("DeriveParameters", BindingFlags.Static | BindingFlags.Public | BindingFlags.InvokeMethod, null, null, new object[]
				{
					dbCommand
				});
			}
			dbConnection.Close();
		}
		if (dbCommand.Parameters.Count > 0 && dbCommand.Parameters[0].Direction == ParameterDirection.ReturnValue)
		{
			dbCommand.Parameters.RemoveAt(0);
		}
		DbParameter[] array = new DbParameter[dbCommand.Parameters.Count];
		dbCommand.Parameters.CopyTo(array, 0);
		return array;
	}

	public static DbParameter[] smethod_1(DbParameter[] dbParameter_0)
	{
		int num = dbParameter_0.Length;
		DbParameter[] array = new DbParameter[num];
		for (int i = 0; i < num; i++)
		{
			array[i] = (DbParameter)((ICloneable)dbParameter_0[i]).Clone();
		}
		return array;
	}

	public static DbParameter[] smethod_2(DbContext dbContext_0)
	{
		if (dbContext_0 == null || dbContext_0.Connection == null || dbContext_0.CurrentCommand == null)
		{
			throw new ArgumentNullException("dbContext");
		}
		if (dbContext_0.CurrentCommand.CommandType != CommandType.StoredProcedure || string.IsNullOrEmpty(dbContext_0.CurrentCommand.CommandText))
		{
			throw new InvalidOperationException("命令不是存储过程，或没有设置存储过程。");
		}
		return Class7.smethod_3(dbContext_0.Connection, dbContext_0.CurrentCommand.CommandText);
	}

	public static DbParameter[] smethod_3(DbConnection dbConnection_0, string string_0)
	{
		if (dbConnection_0 == null)
		{
			throw new ArgumentNullException("dbConn");
		}
		if (string.IsNullOrEmpty(string_0))
		{
			throw new ArgumentNullException("spName");
		}
		string key = string.Concat(new string[]
		{
			string_0,
			"###",
			dbConnection_0.ConnectionString,
			"###",
			dbConnection_0.GetType().ToString()
		});
		DbParameter[] array = Class7.hashtable_0[key] as DbParameter[];
		if (array == null)
		{
			lock (Class7.hashtable_0.SyncRoot)
			{
				array = (Class7.hashtable_0[key] as DbParameter[]);
				if (array == null)
				{
					array = Class7.smethod_0(dbConnection_0, string_0);
					Class7.hashtable_0[key] = array;
				}
			}
		}
		return Class7.smethod_1(array);
	}
	/*
	public static DbParameter[] smethod_4(this XmlCommand xmlCommand_0, DbCommand dbCommand_0)
	{
		if (xmlCommand_0 == null)
		{
			throw new ArgumentNullException("xmlCommand");
		}
		if (dbCommand_0 == null)
		{
			throw new ArgumentNullException("dbCommand");
		}
		if (xmlCommand_0.Parameters.Count == 0)
		{
			return new DbParameter[0];
		}
		DbParameter[] array = new DbParameter[xmlCommand_0.Parameters.Count];
		for (int i = 0; i < xmlCommand_0.Parameters.Count; i++)
		{
			XmlCmdParameter xmlCmdParameter = xmlCommand_0.Parameters[i];
			DbParameter dbParameter = dbCommand_0.CreateParameter();
			dbParameter.ParameterName = xmlCmdParameter.Name;
			dbParameter.DbType = xmlCmdParameter.Type;
			dbParameter.Direction = xmlCmdParameter.Direction;
			dbParameter.Size = xmlCmdParameter.Size;
			array[i] = dbParameter;
		}
		return array;
	}
	*/
}
